import logging
import requests

from api.login_api import Mepsking_Login
from config import Base_Host
class Address_Api:
    def get_province(self,Code):
        url=Base_Host+'/api/system/region/getRegionCascade?countryCode={}'.format(Code)
        resp=requests.get(url=url)
        province_id=[]
        id = resp.json().get('result')
        for i in id:
            province_id.append(i.get('id'))
        name=resp.json().get('result')
        province_name =[]
        for i in name:
            province_name.append(i.get('regionName'))
        # logging.info('{}获取省份接口返回得数据为：{},{}'.format(Code,province_id,province_name))
        return (Code,province_id,province_name)
    def get_city(self,pro_list):
        city_data=[]
        for i in pro_list:
            for y in i[2]:
                url = Base_Host + '/api/system/region/getRegionCascade?countryCode={}&regionOneName={}'.format(i[0], y)
                resp=requests.get(url=url)
                # city_data.append(y)
                # logging.info('{},{}省下面的市接口返回得数据为：{}'.format(i[0],y,resp.json()))
        # print(city_data)
                id_data=[]
                name_data=[]
                city_resp=resp.json().get('result')
                # print(city_resp)
                for x in city_resp:
                    id_data.append(x.get('id'))
                city_data.extend(id_data)
                # city_data.append(id_data)
        # # print('ggggg',city_data)
        #         for a in city_resp:
        #             name_data.append(a.get('regionName'))
        #         city_data.append(name_data)
        return city_data
        # print('最终数据为：',city_data)
    # def get_city01(self,pro_list):
if __name__ == '__main__':
    resp=Address_Api()
    # login = Mepsking_Login()
    # json_dict = {"account": "2524726232@qq.com", "password": "8c730e7f3dac741443cd3a57cdb7fd8f", "sourceFrom": "PC"}
    # token = login.token(json_dict)
    # main=resp.get_city('CN',['Guangdong','Jiangxi'])
    data01 =[('SR', ['1556476796625653761', '1556476798773137410', '1556476800970952706', '1556476801944031233', '1556476804091514882', '1556476805643407362', '1556476807535038465', '1556476811561570307', '1556476813725831170', '1556476817555230722'], ['Brokopondo', 'Commewijne', 'Coronie', 'Marowijne', 'Nickerie', 'Para', 'Paramaribo', 'Saramacca', 'Sipaliwini', 'Wanica']), ('TG', ['1556477931390406658'], ['Lome']), ('TH', ['1556477553018048514', '1556477555421384706', '1556477558009270273', '1556477574237032449', '1556477577093353477', '1556477585003810817', '1556477589810483202', '1556477592427728898', '1556477599247667205', '1556477602762493954', '1556477611734110212', '1556477617639690242', '1556477621267763202', '1556477622245036034', '1556477625218797571', '1556477625671782402', '1556477633359941633', '1556477639085166594', '1556477643472408578', '1556477652490162180', '1556477655203876865', '1556477659951828993', '1556477662556491781', '1556477667161837569', '1556477672098533378', '1556477674434760705', '1556477679614726146', '1556477681967730690', '1556477683867750402', '1556477689005772801', '1556477693581758469', '1556477705728462850', '1556477711063617537', '1556477719829712900', '1556477725533966337', '1556477729833127941', '1556477732957884417', '1556477736527237122', '1556477738733441026', '1556477741568790530', '1556477746224467970', '1556477746744561667', '1556477749672185857', '1556477753254121477', '1556477756445986817', '1556477761516900354', '1556477764557770754', '1556477768777240581', '1556477772350787586', '1556477778625466370', '1556477781934772225', '1556477783176286209', '1556477788142342146', '1556477791388733442', '1556477794945503234', '1556477798707793924', '1556477801891270659', '1556477810825138178', '1556477817716379650', '1556477825769443329', '1556477826356645890', '1556477829544316929', '1556477831213649921', '1556477833218527233', '1556477839853916162', '1556477842911563777', '1556477854613671937', '1556477856878596100', '1556477866378694658', '1556477870916931585', '1556477875459362818', '1556477884095434754', '1556477892081389570', '1556477895457804289', '1556477899794714626', '1556477902332268546', '1556477911362605057', '1556477918723608578', '1556477921768673281', '1556477924809543681', '1556477927540035585'], ['Amnat Charoen', 'Ang Thong', 'Bangkok', 'Bueng Kan', 'Buri Ram', 'Chachoengsao', 'Chai Nat', 'Chaiyaphum', 'Chanthaburi', 'Chiang Mai', 'Chiang Rai', 'Chon Buri', 'Chonburi', 'Chumphon', 'Huay Kwang', 'Kalasin', 'Kamphaeng Phet', 'Kanchanaburi', 'Khon Kaen', 'Krabi', 'Lampang', 'Lamphun', 'Loei', 'Lop Buri', 'Mae Hong Son', 'Maha Sarakham', 'Mukdahan', 'Nakhon Nayok', 'Nakhon Pathom', 'Nakhon Phanom', 'Nakhon Ratchasima', 'Nakhon Sawan', 'Nakhon Si Thammarat', 'Nan', 'Narathiwat', 'Nong Bua Lam Phu', 'Nong Khai', 'Nonthaburi', 'Pathum Thani', 'Pattani', 'Phang Nga', 'Phang-nga', 'Phatthalung', 'Phayao', 'Phetchabun', 'Phetchaburi', 'Phichit', 'Phitsanulok', 'Phra Nakhon Si Ayutthaya', 'Phrae', 'Phuket', 'Prachin Buri', 'Prachuap Khiri Khan', 'Ranong', 'Ratchaburi', 'Rayong', 'Roi Et', 'Sa kaeo', 'Sakon Nakhon', 'Samut Prakan', 'Samut Prakarn', 'Samut Sakhon', 'Samut Songkhram', 'Saraburi', 'Satun', 'Si Sa Ket', 'Sing Buri', 'Songkhla', 'Sukhothai', 'Suphan Buri', 'Surat Thani', 'Surin', 'Tak', 'Trang', 'Trat', 'Ubon Ratchathani', 'Udon Thani', 'Uthai Thani', 'Uttaradit', 'Yala', 'Yasothon']), ('TR', ['1556477932883578881', '1556477936012529666', '1556477940777259010', '1556477944690544641', '1556477948062765057', '1556477953062375426', '1556477954048036865', '1556477961828470785'], ['Akdeniz', 'Dogu Anadolu', 'Ege', 'Guneydogu Anadolu', 'Ic Anadolu', 'Istanbul', 'Karadeniz', 'Marmara']), ('TW', ['1556477454980386818', '1556477461238288385', '1556477462018428929', '1556477466762186753', '1556477467810762753', '1556477471002628098', '1556477474374848514', '1556477486647382018', '1556477488731951106', '1556477493366657026', '1556477494071300097', '1556477497204445186', '1556477504984879105', '1556477514111684609', '1556477522349297666', '1556477531836813314', '1556477534827352066', '1556477538207961089', '1556477541437575169', '1556477544897875970'], ['Changhua County', 'Chiayi City', 'Chiayi County', 'Hsinchu City', 'Hsinchu County', 'Hualien County', 'Kaohsiung City', 'Keelung City', 'Miaoli County', 'NanHai Island', 'Nantou County', 'New Taipei City', 'Pingtung County', 'Taichung City', 'Tainan City', 'Taipei City', 'Taitung County', 'Taoyuan City', 'Yilan County', 'Yunlin County']), ('TZ', ['1556477550820233218'], ['DAR ES SALAAM REGION']), ('UG', ['1556477966635143170'], ['Kampala']), ('US', ['1556477974704984065', '1556478136911302657', '1556478201662967810', '1556478286383714306', '1556478456722788354', '1556478751636885505', '1556478863272480770', '1556478938212110337', '1556478955584917505', '1556478958021808130', '1556479133356298242', '1556479327217029121', '1556479352261218306', '1556479425216942081', '1556479704582754305', '1556479917418516482', '1556480206276038657', '1556480385037275138', '1556480756245762050', '1556480897560252418', '1556481029919903746', '1556481151479222274', '1556481303946366978', '1556481558322515970', '1556481822463004674', '1556481943900688385', '1556482261900234754', '1556482375792365570', '1556482526590177281', '1556482551948939266', '1556482620798439425', '1556482791657607169', '1556482910977167362', '1556483224849518594', '1556483453929820162', '1556483561081704449', '1556483851478536194', '1556484031204462593', '1556484149458669569', '1556484441696800770', '1556484464362819585', '1556484624174190593', '1556484728503308289', '1556484885768736769', '1556485191080513538', '1556485256201277442', '1556485335389736962', '1556485577921171457', '1556485718417772545', '1556485939105271810', '1556486165371195394'], ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Dist. Of Columbia', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']), ('UY', ['1556486213823795201', '1556486231133687809', '1556486302709485569', '1556486335072735234', '1556486375866535938', '1556486398519971842', '1556486408473055234', '1556486441197015042', '1556486466278952962', '1556486490018713602', '1556486490735939586', '1556486513808805889', '1556486526295248898', '1556486553914740738', '1556486576605925377', '1556486593517359105', '1556486618519605250', '1556486636026630146', '1556486665223180290'], ['Artigas', 'Canelones', 'Cerro Largo', 'Colonia', 'Durazno', 'Flores', 'Florida', 'Lavalleja', 'Maldonado', 'Montevideo', 'Paysandu', 'Rio Negro', 'Rivera', 'Rocha', 'Salto', 'San Jose', 'Soriano', 'Tacuarembo', 'Treinta y Tres']), ('UZ', ['1556486686454747137', '1556486687239081986'], ['Tashkent city', 'Tashkent province']), ('VE', ['1556486692716843010', '1556486694977572865', '1556486702317604867', '1556486704519614465', '1556486709837991937', '1556486713382178817', '1556486716313997316', '1556486720197922818', '1556486720390860802', '1556486722420903938', '1556486725407248386', '1556486731048587267', '1556486735150616578', '1556486737881108482', '1556486743203680258', '1556486748626915331', '1556486750715678722', '1556486755467825154', '1556486758907154433', '1556486761562148869', '1556486768696659973', '1556486773335560195', '1556486773922762753', '1556486777445978115'], ['Amazonas', 'Anzoategui', 'Apure', 'Aragua', 'Barinas', 'Bolivar', 'Carabobo', 'Caracas', 'Cojedes', 'Delta Amacuro', 'Falcon', 'Guarico', 'Lara', 'Merida', 'Miranda', 'Monagas', 'Nueva Esparta', 'Portuguesa', 'Sucre', 'Tachira', 'Trujillo', 'Vargas', 'Yaracuy', 'Zulia']), ('VN', ['1556486782592389121', '1556486786899939330', '1556486790548983809', '1556486794957197314', '1556486798966951937', '1556486801584197633', '1556486807124873218', '1556486811042353153', '1556486815685447683', '1556486819586150402', '1556486823570739205', '1556486827484024833', '1556486830923354114', '1556486834597564418', '1556486840649945090', '1556486843749535746', '1556486849520898050', '1556486853178331137', '1556486857070645251', '1556486861990563842', '1556486866553966593', '1556486873155801089', '1556486877694038017', '1556486880659410946', '1556486894467059714', '1556486899718328321', '1556486905984618498', '1556486912464818178', '1556486915572797441', '1556486924921901058', '1556486929082650625', '1556486929535635457', '1556486933914488833', '1556486938586943489', '1556486944962285570', '1556486949987061761', '1556486953116012545', '1556486957679415298', '1556486963396251650', '1556486967296954370', '1556486973152202754', '1556486977778520066', '1556486988000038913', '1556486991615528962', '1556486994287300610', '1556486999622455298', '1556487003401523202', '1556487006828269569', '1556487014357045250', '1556487020044521473', '1556487025614557186', '1556487029985021953', '1556487034003165185', '1556487038910500865', '1556487042890895362', '1556487047898894337', '1556487051858317313', '1556487064294428674', '1556487067989610498', '1556487072402018306', '1556487075715518465', '1556487078706057217', '1556487081822425090', '1556487085903482881', '1556487086419382273'], ['An Giang', 'Ba Ria - Vung Tau', 'Bac Giang', 'Bac Kan', 'Bac Lieu', 'Bac Ninh', 'Ben Tre', 'Binh Dinh', 'Binh Duong', 'Binh Phuoc', 'Binh Thuan', 'Ca Mau', 'Can Tho', 'Cao Bang', 'Da Nang', 'Dak Lak', 'Dak Nong', 'Dien Bien', 'Dong Nai', 'Dong Thap', 'Gia Lai', 'Ha Giang', 'Ha Nam', 'Ha Noi', 'Ha Tinh', 'Hai Duong', 'Hai Phong', 'Hau Giang', 'Ho Chi Minh', 'Hoa Binh', 'Hue', 'Hung Yen', 'Khanh Hoa', 'Kien Giang', 'Kon Tum', 'Lai Chau', 'Lam Dong', 'Lang Son', 'Lao Cai', 'Long An', 'Nam Dinh', 'Nghe An', 'Ninh Binh', 'Ninh Thuan', 'Phu Tho', 'Phu Yen', 'Quang Binh', 'Quang Nam', 'Quang Ngai', 'Quang Ninh', 'Quang Tri', 'Soc Trang', 'Son La', 'Tay Ninh', 'Thai Binh', 'Thai Nguyen', 'Thanh Hoa', 'Thua Thien Hue', 'Tien Giang', 'Tra Vinh', 'Tuyen Quang', 'Vinh Long', 'Vinh Phuc', 'Vung Tau', 'Yen Bai']), ('ZA', ['1556476218566676482', '1556476220315701249', '1556476221804679170', '1556476223306240001'], ['Eastern Cape', 'Gauteng', 'KwaZulu Natal', 'Western Cape']), ('ZM', ['1556487092085886978'], ['LUSAKA']), ('ZW', ['1556487092538871809'], ['HARARE'])]
    resp1=resp.get_city(data01)
    print('dsds',resp1)


